<template>
  <el-container class="home-container">
    <el-header class="home-header">
      <div class="nav_left">
        <img src="../../assets/home-logo.png" alt="" />
        <h2>后台管理系统</h2>
      </div>
      <el-button @click="logout" class="logout">退出</el-button>
    </el-header>

    <el-container>
      <el-aside :width="isCollapse ? '60px' : '200px'">
        <h3 class="collapse" @click="changeMenuWidth">|||</h3>
        <el-menu
          class="menu"
          :collapse="isCollapse"
          background-color="#2E2E2E"
          text-color="#ddd"
          :unique-opened="true"
          :collapse-transition="false"
          :router="true"
          active-text-color="#f40"
          :default-active="$route.path"
        >
          <el-submenu :index="menu.path" v-for="menu in menuData" :key="menu.id">
            <template slot="title">
              <i :class="'iconfont icon-' + menu.path"></i>
              <span slot="title">{{ menu.authName }}</span>
            </template>

            <el-menu-item :index="'/home/' + item.path" v-for="item in menu.children" :key="item.id" :route="item">
              <template slot="title">
                <i class="el-icon-menu"></i>
                <span slot="title">{{ item.authName }}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>

      <el-main>
        <router-view></router-view>
        <el-backtop  :visibility-height='500' :bottom="100">
        <div
          style="
             {
              height: 100%;
              width: 100%;
              background-color: #ccc;
              box-shadow: 0 0 6px rgba(0, 0, 0, 0.12);
              text-align: center;
              line-height: 40px;
              color: #1989fa;
            }
          "
        >
          UP
        </div>
      </el-backtop>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      isCollapse: false,
      menuData: [],
     
    }
  },
  created() {
    this.getMenuData()
  },
  methods: {
    logout() {
      this.$store.dispatch('logout', { token: '' }).then(() => {
        this.$router.replace('/')
        this.$message.success('已退出登录')
      })
    },
    changeMenuWidth() {
      this.isCollapse = !this.isCollapse
    },
    async getMenuData() {
      this.menuData = await this.$store.dispatch('getRequest', { path: '/menus' })
    },
  },
}
</script>

<style lang="less" scoped>
.el-container.home-container {
  height: 100%;
  .el-header.home-header {
    background: #404040;
    display: flex;
    justify-content: space-between;
    padding: 0 30px;
    div.nav_left {
      display: flex;
      img {
        height: 50px;
        margin-top: 5px;
      }
      h2 {
        color: #eee;
        margin: 15px 30px;
      }
    }
    .el-button.logout {
      height: 35px;
      padding: 0px 20px;
      margin-top: 10px;
    }
  }
  & > .el-container {
    .el-aside {
      background: #2e2e2e;
      h3.collapse {
        height: 35px;
        cursor: pointer;
        margin: 0;
        text-align: center;
        line-height: 35px;
        color: #ddd;
      }
      .el-menu.menu {
        border: none;
        .el-submenu {
          i.iconfont {
            margin-right: 10px;
          }
        }
      }
    }
    .el-main {
      background: #eee;
    }
  }
}
</style>
